﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using rent_car.Manejadores;
namespace rent_car.Gui
{
    public partial class FormMantenimientoDeVehiculos : Form
    {
        public FormMantenimientoDeVehiculos()
        {
            InitializeComponent();
            manejadorDeVehiculos = ManejadorDeVehiculos.getInstancia();
            cargarGvVehiculos();
        }

        private void cargarGvVehiculos()
        {
           gvVehiculos.DataSource = manejadorDeVehiculos.getObject();
        }

        private void btnModificar_Click(object sender, EventArgs e)
        {
            modificarVehiculo();
        }

        private void gvVehiculos_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            modificarVehiculo();
        }
        private void modificarVehiculo()
        {
            if (gvVehiculos.SelectedRows.Count != 0)
            {
                vehiculo vehiculoAModificar = (vehiculo)gvVehiculos.CurrentRow.DataBoundItem;
                new FormNuevoVehiculo(vehiculoAModificar).ShowDialog();
            }
        }

        private void FormMantenimientoDeVehiculos_MouseClick(object sender, MouseEventArgs e)
        {
            if (gvVehiculos.SelectedRows.Count != 0)
            {
                vehiculo vehiculoActual = (vehiculo)gvVehiculos.CurrentRow.DataBoundItem;
                if (vehiculoActual.img_vehiculo != null)
                {
                    pbImagenVehiculo.ImageLocation = vehiculoActual.img_vehiculo;
                }
                else
                {
                    pbImagenVehiculo.ImageLocation = ConfigurationManager.AppSettings["pathImagenDefault"];
                }
            }
        }

        private ManejadorDeVehiculos manejadorDeVehiculos = null;
    }
}
